package com.fr.data.impl;

import com.fr.base.FRContext;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.file.DatasourceManager;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;

public class NameTextDatasource extends DirectoryConnection
{
  private String name = null;

  public NameTextDatasource()
  {
  }

  public NameTextDatasource(String paramString)
  {
    setName(paramString);
  }

  public String getName()
  {
    return this.name;
  }

  public void setName(String paramString)
  {
    this.name = paramString;
  }

  private DirectoryConnection createTextDatasource()
  {
    DatasourceManager localDatasourceManager = FRContext.getDatasourceManager();
    Connection localConnection = localDatasourceManager.getConnection(getName());
    if (localConnection instanceof DirectoryConnection)
      return ((DirectoryConnection)localConnection);
    throw new RuntimeException("Cannot found TextDatasource with the name: " + this.name);
  }

  public String getLocation()
  {
    return createTextDatasource().getLocation();
  }

  public void setLocation(String paramString)
  {
    createTextDatasource().setLocation(paramString);
  }

  public boolean equals(Object paramObject)
  {
    return ((paramObject instanceof NameTextDatasource) && (ComparatorUtils.equals(getName(), ((NameTextDatasource)paramObject).getName())));
  }

  public String toString()
  {
    return "[" + getName() + " Database]";
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if ((paramXMLableReader.isChildNode()) && ("DatabaseName".equals(paramXMLableReader.getTagName())))
    {
      String str;
      if ((str = paramXMLableReader.getElementValue()) != null)
        setName(str);
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    if (getName() != null)
      paramXMLPrintWriter.startTAG("DatabaseName").textNode(getName()).end();
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    return super.clone();
  }
}